<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('京东推荐商品详情')" />
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<!--<input type="hidden" id="data" value="${sellNo}" />-->
<div class="col-sm-12 select-table table-striped">
<!--    <input type="checkbox" name="test">-->
    <table id="bootstrap-table"></table>
</div>
<input type="hidden" th:value="${goodsCode}" id="goodsCode"/>

<div>


</div>
<th:block th:include="include :: footer" />

<script >
    var ctx = "[[@{/}]]";
</script>
<!--<script th:inline="javascript">-->
<script>
    var prefix = ctx + "jd/goods";

    var fileName=$("#goodsCode").val();
    console.log("文件名" + "  " + fileName);


    $(function() {
        console.log('参数： ' + fileName)
        var options = {
            url : ctx +"jd/goodsCode" ,
            createUrl: prefix + "/add",
            modalName: "京东推荐商品明细",
            // 测试新增 查询条件
            queryParams: function(params) {
                var curParams = {
                    // 传递参数查询参数
                    pageSize: params.limit,
                    pageNum: params.offset / params.limit + 1,
                    searchValue: params.search,
                    orderByColumn: params.sort,
                    isAsc: params.order,

                    goodsCode: $("#goodsCode").val()
                }
                return curParams;
            },
            columns: [
                {
                    field: 'id',
                    title: '序号',
                    width: 50,
                    visible: false
                },
                {
                    field: 'jdtj_id',
                    title: '商品编号',
                    width: 50,
                    //visible: false
                },

                {
                    field: 'goodsName',
                    title: '商品名称',
                    width: 200,
                },
                {
                    field: 'goodsPicUrl',
                    title: '商品图片',
                    detailView : true,
                    width: 120,
                    formatter: function (value) {
                        let url = 'http://' + value;
                        console.log(url);
                        return '<img loading="lazy" src="'+ url +'" alt="Smiley face" width="100" height="100">'
                    }
                },
                {
                    field: 'goodsPrice',
                    title: '单价',
                    align: "right",
                    width: 50,

                },
                {
                    field: 'commission',
                    title: '佣金',
                    align: "right",
                    width: 50,
                },

                {
                    title: '操作',
                    align: 'center',
                     width: 100,
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');row.sellNo + row.startTime + row.endTime*/
                        //actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="jdReferralLink(\'' + row.referralLink +"','"+ row.createTime+ "','"+ row.goodsNum+ '\')"><i class="fa fa-edit"></i>京东</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="submitSave(\'' + row.id +'\')"><i class="fa fa-edit"></i>删除</a> ');
                        /* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        // actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        //actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                },


                ]
        };
        $.table.init(options);

    });

</script>
<script>
    function  jdReferralLink(p1,p2,p3){

        if(p1 != null){
            console.log('京东推广链接：' + p1);
            window.open(p1)
        }
        //window.parent.$('#bootstrap-table').bootstrapTable('refresh');
    }

    /* 选取 保存记录 */
    function submitSave(id) {
        var goodsCode = $("#goodsCode").val();
        console.log(goodsCode);

        $.ajax({
            type: 'post',
            url: ctx +'jd/goods' + '/delete',
            timeout: 30000,
            //	data : queryParams,
            data: {"id":id},
            dataType: 'json',
            success: function (data) {
                console.log(data);


                //$.table.bootstrapTable('refresh');
                window.parent.$('#bootstrap-table-goods').bootstrapTable('refresh');
                $.table.refresh()
                alert("操作成功");
                /*if(data.code == 0) {
                    //alert("数据插入成功")
                    // 刷新父页面表格
                    window.parent.$('#bootstrap-table').bootstrapTable('refresh');
                    $.operate.successCallback(data);

                }else{
                    alert("数据插入异常")
                }*/

            },
            error: function () {
                alert("调用数据接口失败,请联系管理员");
            }
        });
    }

</script>

</body>
</html>
